Dart Uri operator ==
Syntax & Examples


Uri.operator == operator

The `operator ==` in Dart checks if a URI is equal to another URI with the same normalized representation.


Syntax of Uri.operator ==

The syntax of Uri.operator == operator is:

operator ==(Object other) → bool

This operator == operator of Uri a URI is equal to another URI with the same normalized representation.

Parameters

ParameterOptional/RequiredDescription


✐ Examples

1 Comparing equal URIs

In this example,

  1. We create two URIs using `Uri.parse()` with the same normalized representation.
  2. We use the `==` operator to check if the URIs are equal.
  3. We then print the result of the comparison.

Dart Program

void main() {
  Uri uri1 = Uri.parse('https://example.com');
  Uri uri2 = Uri.parse('https://example.com');
  bool isEqual = uri1 == uri2;
  print('Are URIs equal? $isEqual');
}

Output

Are URIs equal? true

2 Comparing unequal URIs

In this example,

  1. We create two URIs using `Uri.parse()` with different normalized representations.
  2. We use the `==` operator to check if the URIs are equal.
  3. We then print the result of the comparison.

Dart Program

void main() {
  Uri uri1 = Uri.parse('https://example.com');
  Uri uri2 = Uri.parse('https://anotherdomain.com');
  bool isEqual = uri1 == uri2;
  print('Are URIs equal? $isEqual');
}

Output

Are URIs equal? false

3 Comparing URIs with different ports

In this example,

  1. We create two URIs using `Uri.parse()` with the same host but different ports.
  2. We use the `==` operator to check if the URIs are equal.
  3. We then print the result of the comparison.

Dart Program

void main() {
  Uri uri1 = Uri.parse('https://example.com');
  Uri uri2 = Uri.parse('https://example.com:443');
  bool isEqual = uri1 == uri2;
  print('Are URIs equal? $isEqual');
}

Output

Are URIs equal? true

Summary

In this Dart tutorial, we learned about operator == operator of Uri: the syntax and few working examples with output and detailed explanation for each example.